<%--
  Created by IntelliJ IDEA.
  User: zhong
  Date: 2020/5/13
  Time: 16:00
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="/manage/inc/header"/>
<jsp:include page="/manage/inc/menu"/>
<div class="main-wrap">
    <div class="crumb-wrap">
        <div class="crumb-list"><i class="icon-font"></i><a href="${pageContext.request.contextPath}/manage/index">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">添加管理员</span></div>
    </div>
    <div class="result-wrap">
        <form action="${pageContext.request.contextPath}/manage/position/insert" method="post" id="myform" name="myform">
            <div class="config-items">
                <div class="config-title">
                    <h1><i class="icon-font">&#xe00a;</i>添加职业</h1>
                </div>
                <div class="result-content">
                    <table width="100%" class="insert-tab">
                        <tbody>
                        <tr>
                            <th width="15%"><i class="require-red">*</i>输入职业名称:</th>
                            <td><input type="text" id="name" placeholder="请输入职业名称" size="50" name="name" class="common-text"><span></span></td>
                        </tr>
                        <tr>
                            <th>  选择分类:</th>
                            <td>
                                <select name="typeId" id="typeId">
                                    <c:forEach items="${requestScope.positionTypes}" var="positionType">
                                        <option value="${positionType.id}">${positionType.positionTypeName}</option>
                                    </c:forEach>
                                </select>
                                <span></span>
                            </td>
                        </tr>
                        <tr>
                            <th>请输入热度:</th>
                            <td><input type="number" value="1" name="heat" id="heat"><span></span></td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input type="submit" value="提交" class="btn btn-primary btn6 mr10">
                                <input type="button" value="返回" onclick="history.go(-1)" class="btn btn6">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </form>
    </div>
</div>
<jsp:include page="/manage/inc/footer"/>
<script>
    $(function () {
        $("#name").blur(isRename);
        $("#myform").submit(check);
    });
    function isRename() {
        var name = $("#name").val();
        var regExp = /^[\w\u4e00-\u9fa5]{2,50}$/;
        var flag = regExp.test(name);
        if(flag==false)//非法
        {
            $("#name").next().html("不符合命名规则");
            return false;
        }
        else{
            var f=false;
            $.ajax({
                url:"${pageContext.request.contextPath}/manage/position/isRename",
                type:"post",
                async:false,
                data:"name="+name,
                success:function(mes){
                    if(mes=="1")//不重复
                    {
                        $("#name").next().html("√");
                        f = true;
                    }
                    if(mes=="0")//重复
                    {
                        $("#name").next().html("行业已存在");
                        f = false;
                    }
                }
            });
            return f;
        }
    }
    function check() {
        var fname = isRename();
        if(fname){
            alert("添加成功");
        }
        else{
            alert("添加失败");
        }
        return fname;
    }
</script>
